package tp.pr2;

/**
 * The garbage is a type of item that generates recycled material after using
 * it. The garbage can be used only once. After using it, it must be removed
 * from the robot inventory.
 * 
 */
public class Garbage extends Item {

	private int recycledMaterial;
	private boolean used; // Flag of the usage of the item

	/**
	 * Garbage constructor
	 * 
	 * @param id
	 *            - Item id
	 * @param description
	 *            - Item description
	 * @param recycledMaterial
	 *            - The amount of recycled material that the item generates
	 */
	public Garbage(java.lang.String id, java.lang.String description,
			int recycledMaterial) {
		super(id, description);
		this.recycledMaterial = recycledMaterial;
		this.used = false;
	}

	@Override
	/**
	 * Garbage can be used only once
	 */
	public boolean canBeUsed() {
		return !used;
	}

	@Override
	/**
	 * The garbage generates recycled material for the robot that uses it
	 * return - true iff the garbage was transformed into recycled material
	 */
	public boolean use(RobotEngine r, Place p) {
		if (canBeUsed()) {
			r.addRecycledMaterial(recycledMaterial);
			System.out.println(r.statusInfo());
			used = true;
			return true;
		} else
			return false;
	}

	@Override
	public java.lang.String toString() {
		return id + ": " + description + "// recycled material = " + recycledMaterial;
	}

}
